﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FI.Core.SettingSource.Configuration
{
    /// <summary>
    /// The simple configuration file based setting source.
    /// </summary>
    public class SimpleFileSettingSourceData : SettingSourceDataBase
    {
        #region Constants
        private const string ConfigurationFilePathProperty = "filePath";
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the file path.
        /// </summary>
        /// <value>
        /// The file path.
        /// </value>
        [ConfigurationProperty(ConfigurationFilePathProperty, IsRequired = false, DefaultValue= "")]
        public string FilePath
        {
            get { return (string)base[ConfigurationFilePathProperty]; }
            set { base[ConfigurationFilePathProperty] = value; }
        }
        #endregion

        #region Public Methods
        /// <summary>
        /// Creates the setting source.
        /// </summary>
        /// <returns>
        /// The created setting source.
        /// </returns>
        public override ISettingSource CreateSettingSource()
        {
            if (string.IsNullOrEmpty(this.FilePath))
            {
                return new SimpleFileSettingSource();
            }
            return new SimpleFileSettingSource(this.FilePath);
        }
        #endregion
    }
}
